package xyz.xtt.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import xyz.xtt.admin.entity.TblChainTransaction;
import xyz.xtt.admin.entity.TblCollection;
import xyz.xtt.admin.request.CollectionTopRequest;
import xyz.xtt.admin.service.ICollectionService;
import xyz.xtt.common.response.ApiResult;

import java.util.Optional;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/api/admin/collection")
public class CollectionController {


    @Autowired
    private ICollectionService iCollectionService;

    @GetMapping("/list")
    public ApiResult<Page<TblCollection>> getList(Integer current, Integer pageSize) {
        current = Optional.ofNullable(current).filter(x->x>1).orElse(1);
        pageSize = Optional.ofNullable(pageSize).filter(x->x>1).orElse(20);
        return ApiResult.ok(iCollectionService.getList(current, pageSize));
    }

    @PostMapping("/top")
    public ApiResult<?> top(@Validated @RequestBody CollectionTopRequest collectionTopRequest) {
        Long id = Long.parseLong(collectionTopRequest.getId());

        if (iCollectionService.setTop(id, collectionTopRequest.getTopStatus())) {
           return ApiResult.ok();
        }
        return  ApiResult.failure(21, "提交失败");
    }
}
